package com.pleasure.gm.criminalintent;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Date;
import java.util.UUID;

/**
 * Created by Administrator on 2016-01-05.
 */
public class Crime {
    private UUID mID;
    private String mTitle;
    private Date mDate;
    private boolean mSolved;

    public String getSuspsect() {
        return mSuspsect;
    }

    public void setSuspsect(String mSuspsect) {
        this.mSuspsect = mSuspsect;
    }

    private String mSuspsect;

    private static final String JSON_ID = "id";
    private static final String JSON_TITLE = "title";
    private static final String JSON_SOLVED = "solved";
    private static final String JSON_DATE = "date";
    private static final String JSON_SUSPSECT = "suspect";

    public Crime(){
        mID = UUID.randomUUID();
        mDate = new Date();

    }

    public UUID getId(){
        return mID;
    }

    public String getTitle(){
        return mTitle;
    }

    public void setTitle(String s){
        mTitle = s;
    }

    public Date getmDate() {
        return mDate;
    }

    public void setmDate(Date mDate) {
        this.mDate = mDate;
    }

    public boolean ismSolved() {
        return mSolved;
    }

    public void setmSolved(boolean mSolved) {
        this.mSolved = mSolved;
    }

    @Override
    public String toString() {
        return mTitle;
    }

    public JSONObject toJSON() throws JSONException {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(JSON_ID,mID.toString());
        jsonObject.put(JSON_TITLE,mTitle);
        jsonObject.put(JSON_SOLVED,mSolved);
        jsonObject.put(JSON_DATE,mDate.getTime());
        jsonObject.put(JSON_SUSPSECT,mSuspsect);

        return jsonObject;
    }

    public Crime(JSONObject json) throws JSONException {
        mID = UUID.fromString(json.getString(JSON_ID));
        mTitle = json.getString(JSON_TITLE);
        mSolved = json.getBoolean(JSON_SOLVED);
        mDate = new Date(json.getLong(JSON_DATE));

        if(json.has(JSON_SUSPSECT))
            mSuspsect = json.getString(JSON_SUSPSECT);
    }
}
